package handlers

import (
	"github.com/gin-gonic/gin"
	"repo-master1/models"
	"strconv"
)

func FindRoleNode(c *gin.Context) {
	rid, _ := strconv.Atoi(c.Query("rid"))
	if rid == 0 {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "数据不能为空",
		})
		return
	}

	var node []models.Node

	models.DB.Table("nodes").
		Joins("LEFT JOIN role_nodes ON role_nodes.nid = nodes.id").
		Where("role_nodes.rid =  ?", rid).
		Find(&node)

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": node,
	})
	return
}
